<?php
/**
 * Created by PhpStorm.
 * User: Deann.wu
 * Date: 2018/3/20 0020
 * Time: 14:21
 */
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Models\Types;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Qiniu\Http\Client;

class TypeController extends Controller{

    public function __construct()
    {
        parent::__construct();
        //标签
        View::share('keyword','');
        //标题
        View::share('title','分类信息');
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author Deann.wu
     * @name 根据分类id获取数据
     */
    public function getList($type_id){
        //获取分类数据
        $tp_info=Types::getInfoById($type_id);
        //筛选数据
        $lists=Post::getListByTypeId($type_id);
        //模块阐述
        $this->modelElaborate('分类：'.$tp_info->name,'分类归档 "'.$tp_info->name.'"','列表','/home/images/main-dm.jpg');
        return view('home.type.list',compact('lists'));
    }

    public function getTypesList(){
        $lists=Types::getDataBySonList(1);
        //循环得到拥文章的数量
        foreach ($lists as $list){
            $list->p_count=Post::getCountByTypeId($list->id);
        }
        //模块阐述
        $this->modelElaborate('代码知识所有分类'," 一屋不扫，何以扫天下。",'分类列表','/home/images/main-dm.jpg');
        return view('home.type.list_type',compact('lists'));
    }

}